package com.github.zhuyiyi1990.oraclejavaprogrammerexam.ocpjp8.pdf.question28;

class ImageScanner implements AutoCloseable {

    @Override
    public void close() throws Exception {
        System.out.print("Scanner closed.");
    }

    public void scanImage() throws Exception {
        System.out.print("Scan.");
        throw new Exception("Unable to scan.");
    }

}

class ImagePrinter implements AutoCloseable {

    @Override
    public void close() throws Exception {
        System.out.print("Printer closed.");
        throw new Exception("unable to close printer");
    }

    public void printImage() {
        System.out.print("Print.");
    }

}

public class MyTest {

    public static void main(String[] args) {
        try (ImageScanner ir = new ImageScanner(); ImagePrinter iw = new ImagePrinter()) {
            ir.scanImage();
            iw.printImage();
        } catch (Exception e) {
            System.out.print(e.getMessage());
        }
    }

}
